<script setup lang="ts">
import { FileUpload } from "@/components/common/FileUpload";
import { ref } from "vue";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    achievementsDesc: "",
    achievementsName: "",
    achievementsType: "",
    additionFiles: "",
    obtainDate: "",
    score: null,
    userIds: null
  }),
  userList: null
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="160px"
    class="mr-12"
  >
    <el-form-item label="教学成果类型" prop="achievementsType">
      <el-select
        v-model="newFormInline.achievementsType"
        placeholder="请选择"
        clearable
        class="!w-[300px]"
      >
        <el-option label="教改项目" value="教改项目" />
        <el-option label="教学获奖" value="教学获奖" />
        <el-option label="其他" value="其他" />
      </el-select>
    </el-form-item>
    <el-form-item label="教学成果名称" prop="achievementsName">
      <el-input
        v-model="newFormInline.achievementsName"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="成果描述" prop="achievementsDesc">
      <el-input
        v-model="newFormInline.achievementsDesc"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="出生年月" prop="obtainDate">
      <el-date-picker
        v-model="newFormInline.obtainDate"
        type="date"
        placeholder="请选择"
        value-format="YYYY-MM-DD"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="相关附件" prop="additionFiles">
      <FileUpload v-model="newFormInline.additionFiles" :limit="15" />
    </el-form-item>
    <el-form-item label="人员" prop="userIds">
      <el-select
        v-model="newFormInline.userIds"
        clearable
        multiple
        placeholder="请选择"
        class="!w-[300px]"
      >
        <el-option
          v-for="item in props.userList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="获取积分" prop="score">
      <el-input-number
        v-model="newFormInline.score"
        :min="0"
        placeholder="请输入"
        class="!w-[200px]"
      />
    </el-form-item>
  </el-form>
</template>
